package base.thread_JUC2.chapter04.demo03;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
 * 计算阶乘任务
 */
public class FactorialCalculator implements Callable<Integer> {
    private Integer number;
    public FactorialCalculator(Integer number){
        this.number = number;
    }

    /**
     * 计算阶乘任务
     */
    @Override
    public Integer call() throws Exception {
        int result=1;
        for (int i = 1; i <= number; i++) {
            result *= i;
            TimeUnit.MILLISECONDS.sleep(100);//模拟计算耗时
        }
        System.out.printf("%s: %d\n",Thread.currentThread().getName(),result);
        return result;
    }
}
